##=============================================================================
## Appendix Table 12
##=============================================================================

##-----------------
# clear environment
rm(list=ls())
options(stringsAsFactors = FALSE, scipen = 999)
# source("R/functions.R")

##--------
# Set seed
seed <- sample.int(.Machine$integer.max, 1)
set.seed(seed)

##-------------
# Load Packages
ipak <- function(pkg){new.pkg <- pkg[!(pkg %in% installed.packages()[, "Package"])]
if(length(new.pkg)) install.packages(new.pkg, dependencies = TRUE)
sapply(pkg, require, character.only = TRUE)
}

packages <- c("tidyverse", "broom")


ipak(packages)

##---------
# Load Data
load("~/Desktop/clean_ukraine_data.RData")

##--------------------------------------------------------------
# Is there a higher survival mindset among displaced respondents
# across survey waves?
dat %>% 
  mutate(wave = factor(wave, labels = c("July 2022 \n (n = 1,614)", 
                                        "February 2023 \n (n = 1,576)"))) %>%
  group_by(wave) %>% 
  summarize(mean = mean(survival_mindset_z, na.rm = TRUE), 
            sd = sd(survival_mindset_z, na.rm = TRUE), 
            n = sum(!is.na(survival_mindset_z))) %>% 
  mutate(se = sd / sqrt(n),
         lower = mean - qnorm(0.975) * se,
         upper  = mean + qnorm(0.975) * se) %>% 
  dplyr::select(wave, mean, lower, upper) 

rm(list = ls())
##=============================================================================
## End of File
##=============================================================================